package summary;

import java.util.Arrays;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/13 15:13
 * https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/
 */
public class Title674 {


    /**
     * dp[i]表示第i个位置时序列长度
     * 递推公式：if(num[i]>nums[i - 1]) dp[i] = dp[i - 1] + 1
     * @param nums
     * @return
     */
    public static int findLengthOfLCIS(int[] nums) {
        int[] dp = new int[nums.length];
        Arrays.fill(dp, 1);
        int max = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                dp[i] = dp[i - 1] + 1;
                if (max < dp[i]) {
                    max = dp[i];
                }
            }
        }
        return max;
    }


    public static int findLengthOfLCIS1(int[] nums) {
        int max = 1;
        int count = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] > nums[i - 1]) {
                count++;
            }else{
                if (max < count) {
                    max = count;
                }
                count = 1;
            }
        }
        if (max < count) {
            max = count;
        }
        return max;
    }




    public int findLengthOfLCIS4(int[] nums) {
        //dp[i]表示最长连续子序列的长度
        int n = nums.length;
        int[] dp = new int[n];
        Arrays.fill(dp, 1);
        int max = 1;
        for (int i = 1; i < n; i++) {
            //连续
            if (nums[i] > nums[i - 1]) {
                dp[i] = dp[i - 1] + 1;
                if (dp[i] > max) {
                    max = dp[i];
                }
            }
        }
        return max;
    }
















    public static void main(String[] args) {
        int[] arr = {1, 3, 5, 4, 7};
        findLengthOfLCIS(arr);
    }
}
